package com.semidata.rtd.core.datasource.redis;

import com.semidata.rtd.core.datasource.DataSource;
import com.semidata.rtd.core.datasource.DataSourceException;
import com.semidata.rtd.core.datasource.DataSourceReader;
import com.semidata.rtd.core.datasource.DataSourceWriter;
import com.semidata.rtd.core.redis.RedisClient;

public class RedisDataSource implements DataSource {

	private final static int CONNECTNUM = 2;
	private final static int TIMEOUT = 40;
	private final static int CPUCORE = Runtime.getRuntime().availableProcessors();
	public RedisClient client;

	public RedisDataSource() {
		this(new String[] { "127.0.0.1:6379" }, CPUCORE, CONNECTNUM, TIMEOUT);
	}

	public RedisDataSource(String[] hosts) {
		this(hosts, CPUCORE, CONNECTNUM, TIMEOUT);
	}

	public RedisDataSource(String[] hosts, int threadNum, int connectionNum, int timeout) {
		if (hosts == null || hosts.length == 0 || threadNum <= 0 || connectionNum <= 0 || timeout <= 0)
			throw new DataSourceException("no datasource");
		
		client = new RedisClient(hosts, threadNum, connectionNum, timeout);
		client.start();

	}

	public RedisClient getClient() {
		return client;
	}
	
	@Override
	public DataSourceReader getReader() {
		return null;//new RedisReader(this);
	}

	@Override
	public DataSourceWriter getWriter() {
		return null;//new RedisWriter(this);
	}
}
